<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

    <link rel="stylesheet" href="__PUBLIC__/js/jquery-easyui-1.5.1/themes/default/easyui.css">
    <link rel="stylesheet" href="__PUBLIC__/js/jquery-easyui-1.5.1/themes/icon.css">

    <script src="__PUBLIC__/js/jquery-easyui-1.5.1/jquery.min.js"></script>
    <script src="__PUBLIC__/js/jquery-easyui-1.5.1/jquery.easyui.min.js"></script>
    <script src="__PUBLIC__/js/jquery-easyui-1.5.1/plugins/jquery.linkbutton.js"></script>
    <script src="__PUBLIC__/js/jquery-easyui-1.5.1/locale/easyui-lang-zh_CN.js"></script>


    <script>

        $(function () {


            $('#tt').datagrid({
                title: '工时',
                iconCls: 'icon-edit',
                width: '100%',
                height: 'auto',
                singleSelect: true,
                fitColumns: true,
                idField: 'id',
                pagination: true,
                toolbar: '#tb',
                striped:true,
                pageSize:20,

                url: "{:U('home/record/getrecords','')}",
//                toolbar: [
//                    {
//                        text: '新建',
//                        iconCls: 'icon-add',
//                        handler: function () {
//                            $('#win').window({
//                                width:680,
//                                height:460,
//                                fit:true,
//                                modal:true,
//                                content : '<iframe style="width:100%;height:100%;" scrolling="auto" frameborder="0" src="/gs_php/index.php/home/record/add"></iframe>',
//                            });
//                        }
//
//                    },{
//                        text: '编辑',
//                        iconCls: 'icon-add',
//                        handler: function () {
//
//
//
////                            $('#win2').window({
////                                width:680,
////
////                                height:460,
////                                modal:true,
////                                content : '<iframe style="width:100%;height:100%;" scrolling="auto" frameborder="0" src="{:U('home/record/add')}"></iframe>',
////                            });
//                        }
//                    }
//
//                ],
                columns: [[
                    {field: 'id', title: '编码', width: 30},
                    {
                        field: 'name', title: '站点', width: 40,
                        editor: {
                            type: 'textbox',
                            options: {
                                required: true,
                                missingMessage: '必须填写名称'
                            }
                        }
                    },
                    {
                        field: 'content', title: '工作内容', width: 180,
                        editor: {
                            type: 'textbox',
                            options: {
                                required: true,
                                missingMessage: '必须填写名称'
                            }
                        }
                    },


                    {
                        field: 'member', title: '人员', width: 80, align: 'center',
                        formatter: function (value, row, index) {
                            var str = "";
                            if (value) {

                                for (var key in value) {
                                    str = str + value[key].name + "&nbsp&nbsp"
                                }

                            }
                            return str;

                        }
                    },
                    {
                        field: 'starttime', title: '开始时间', width: 80,
                        formatter: function (value) {
                            return new Date(value * 1000).toLocaleDateString();//这个可以更新时间显示
                        }
                    },
                    {
                        field: 'pend', title: '审核-删除', width: 70,
                        formatter: function (value, index) {
                            var d = '----<a href="#" id="link_delete" onclick="deleterow(this)">删除</a>';
                            if (value == '1') {
                                return '<span style="color:blue">已审核</span>'+d;
                            }

                            return '<a href="#" style="color:red"  onclick="pendrow(this)">未审核</a>'+d;
                        }
                    }
                ]],

                onDblClickRow: function (index, row) {
                    var r_id = 'id=' + row.id;
                    var src = "{:U('home/record/edit?')}" + '?' + r_id;//草,只能让我用这个方法输出
                    self.parent.addTab('编辑记录', src);

//                    $('#win').window({
//                                width:680,
//                                height:460,
//                                modal:true,
//                                fit:true,
//                                content : '<iframe style="width:100%;height:100%;" scrolling="auto" frameborder="0" src="'+src+'"></iframe>',
//                });
                },
                /*/
                 定义了loadfilter的方法,但我不打算用.直接从服务器过滤吧
                 */
//                loadFilter: function (data) {
//                    var rows=data.rows;
//                    var returnrows=new Array();
//                    for(var i in rows){
//                        if (rows[i].pend==1) {
//                           // delete rows[i];
//                           returnrows.push(rows[i]);
//                        }
//                    }
//                  //  data.total=returnrows.length;
//                    data.rows=returnrows;
//                    return data;
//                },
            });
        });

        function getRowIndex(target) {
            var tr = $(target).closest('tr.datagrid-row');
            return parseInt(tr.attr('datagrid-row-index'));
        }

        function pendrow(target) {

            var rows = $('#tt').datagrid('getRows');
            var pendid = rows[getRowIndex(target)].id;
            var sss = [1, 2, 3];
            $.messager.confirm('Confirm', '确认审核吗?', function (r) {
                if (r) {

                    var posturl = "{:U('home/record/pendrecord')}";
                    $.post(posturl, {'id': pendid}, function (data) {
                        $.messager.alert('消息', data.info, 'info');
                        $('#tt').datagrid('reload');
                    });


                }
            });
        }
        function deleterow(target){
            var rows = $('#tt').datagrid('getRows');
            var deleteid = rows[getRowIndex(target)].id;
            $.messager.confirm('Confirm','确认删除吗?', function (r) {
                if (r) {
                    var posturl = "{:U('home/record/deleterecord')}";
                    $.post(posturl, {'id': deleteid}, function (data) {
                        $.messager.alert('消息', data.info, 'info');
                        $('#tt').datagrid('reload');
                    });
                }
            })

        }
        function doSearch() {
            $('#tt').datagrid('load', {
                starttime: $('#itemid').datetimebox('getText'),
                donetime: $('#productid').datetimebox('getText'),
                memid:  $('#cc').combobox('getValues'),
                pendid:$('input:checked').val(),
                stationsid:$('#sc').combobox('getValues')

            });
        }

    </script>

</head>
<script>
    function cl() {
        $('#tt').datagrid('reload');
    }
</script>
<body>
<!--<input type="button" onclick="javascript:self.top.closeatab()"> 测试关闭当前选择的tab-->
<table id="tt"></table>
<div id="win"></div>
<div id="win2"></div>
<div id="tb" style="padding:3px">
    <form id="ff" action="">
        <span>
         <span>开始时间</span>
    <input id="itemid" class="easyui-datetimebox"  style="line-height:26px;border:1px solid #ccc">
    <span>结束时间</span>
    <input id="productid" class="easyui-datetimebox"  style="line-height:26px;border:1px solid #ccc">
    </span>
        <span>
     成员选择
    <select id="cc" class="easyui-combobox" data-options="multiple:true" name="dept[]" style="width:200px;">
        <option selected="selected"  value="0">--全部成员--</option>
        <foreach name="members" item="vo">
            <option  value="{$vo.id}">{$vo.name}</option>
        </foreach>
    </select>
        </span>
        <span>
             <select id="sc" class="easyui-combobox" data-options="multiple:true" name="dept[]" style="width:200px;">
                 <option selected="selected"  value="0">--全部站点--</option>
                 <foreach name="stations" item="vo">
                     <option  value="{$vo.id}">{$vo.name}</option>
                 </foreach>
             </select>

        </span>
        <br>

        <input type="radio" checked="checked" value="-1" name="filtermem" >全部显示
        <input type="radio" value="1" name="filtermem">只显示未审核
        <input type="radio" value="0" name="filtermem">只显示已审核
        <span>|</span>
        <a href="#" class="easyui-linkbutton" plain="true" data-options="iconCls:'icon-search'" onclick="doSearch()">Search</a>

    </form>

</div>

</body>
</html>